package com.avcdata.aoscustommade.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import com.avcdata.aoscustommade.R;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created by c.c on 2017/3/1.
 * 多选
 */
public class SelectMuchAdapter extends BaseAdapter {
    private Activity mContext;
    private ArrayList<HashMap<String, String>> dataTemp;
    private int num;

    public SelectMuchAdapter(Activity mContext,ArrayList<HashMap<String, String>> dataTemp, int num) {
        this.mContext = mContext;
        this.dataTemp = dataTemp;
        this.num = num;
    }
    public ArrayList<HashMap<String, String>> getData(){
        return dataTemp;
    }
    @Override
    public int getCount() {
        return dataTemp.size();
    }

    @Override
    public Object getItem(int position) {
        return dataTemp.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressWarnings("deprecation")
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolderSelectMuch vHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_textclick, null);
            vHolder = new ViewHolderSelectMuch();
            vHolder.item_name = (TextView) convertView.findViewById(R.id.item_name);
            vHolder.item_checkbox = (CheckBox) convertView.findViewById(R.id.item_checkbox);
            convertView.setTag(vHolder);
        } else {
            vHolder = (ViewHolderSelectMuch) convertView.getTag();
        }
        HashMap<String, String> hashMap = dataTemp.get(position);
        if (num == 0) {
            String priceSegment = hashMap.get("priceSegment");
            vHolder.item_name.setText(priceSegment);
        } else {
            String name = hashMap.get("name");
            vHolder.item_name.setText(name);
        }

        if (hashMap.get("isCheck").equals("1")){
            vHolder.item_checkbox.setChecked(false);
        }else {
            vHolder.item_checkbox.setChecked(true);
        }
        return convertView;
    }


    private class ViewHolderSelectMuch {
        TextView item_name;
        CheckBox item_checkbox;

    }

}
